package com.atguigui.leetcode1;

/**
 * 1250.检查「好数组」
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/2/15 9:22
 */
public class P1250CheckIfItIsAGoodArray {
    public static void main(String[] args) {
        Solution solution = new P1250CheckIfItIsAGoodArray().new Solution();
        // TO TEST
    }

    class Solution {
        public boolean isGoodArray(int[] nums) {
            int divisor = nums[0];
            for (int num : nums) {
                divisor = gcd(divisor, num);
                if (divisor == 1) {
                    break;
                }
            }
            return divisor == 1;
        }

        //最小公倍数
        private int gcd(int num1, int num2) {
            while (num2 != 0) {
                int temp = num1;
                num1 = num2;
                num2 = temp % num2;
            }
            return num1;
        }
    }
}
